#!/bin/bash
clear
while [  "$op"  !=  "3" ]
do
echo -e "\033[0;37m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
echo -e "\E[44;1;37m            BLOQUEAR USUÁRIO TEMPORÁRIO            \E[0m"
echo -e "\033[0;37m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
echo -e "\033[1;31m• \033[1;37mBLOQUEAR E DESBLOQUEAR USUÁRIO TEMPORARIAMENTE!\033[0m"
echo -e "\033[0;37m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
echo -e "\033[1;31m[\033[1;36m01\033[1;31m]\033[1;37m • \033[1;37mBLOQUEAR USUÁRIO \033[0;32m"
echo -e "\033[1;31m[\033[1;36m02\033[1;31m]\033[1;37m • \033[1;37mDESBLOQUEAR USUÁRIO \033[1;37m"
echo -e "\033[1;31m[\033[1;36m00\033[1;31m]\033[1;37m • \033[1;37mVOLTA AO MENU \033[0;32m"
echo -e "\033[0;37m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
echo -e "\E[44;1;37m Usuario         Senha        limite      validade \E[0m"
[[ ! -e /bin/versao ]] && rm -rf /bin/menu
for users in `awk -F : '$3 > 900 { print $1 }' /etc/passwd |sort |grep -v "nobody" |grep -vi polkitd |grep -vi system-`
do
if [[ $(grep -cw $users $HOME/usuarios.db) == "1" ]]; then
    lim=$(grep -w $users $HOME/usuarios.db | cut -d' ' -f2)
else
    lim="1"
fi
if [[ -e "/etc/SSHPlus/senha/$users" ]]; then
    senha=$(cat /etc/SSHPlus/senha/$users)
else
    senha="Null"
fi
datauser=$(chage -l $users |grep -i co |awk -F : '{print $2}')
if [ $datauser = never ] 2> /dev/null
then
data="\033[1;37mNunca\033[0m"
else
    databr="$(date -d "$datauser" +"%Y%m%d")"
    hoje="$(date -d today +"%Y%m%d")"
    if [ $hoje -ge $databr ]
    then
    data="\033[1;31mVenceu\033[0m"
    else
    dat="$(date -d"$datauser" '+%Y-%m-%d')"
    data=$(echo -e "$((($(date -ud $dat +%s)-$(date -ud $(date +%Y-%m-%d) +%s))/86400)) \033[1;37mDias\033[0m")
    fi
fi
Usuario=$(printf ' %-15s' "$users")
Senha=$(printf '%-13s' "$senha")
Limite=$(printf '%-10s' "$lim")
Data=$(printf '%-1s' "$data")
echo -e "\033[1;37m$Usuario \033[1;37m$Senha \033[1;37m$Limite \033[1;32m$Data\033[0m"
echo -e "\033[0;37m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m"
done
_tuser=$(awk -F: '$3>=1000 {print $1}' /etc/passwd | grep -v nobody | wc -l)
_ons=$(ps -x | grep sshd | grep -v root | grep priv | wc -l)
[[ "$(cat /etc/SSHPlus/Exp)" != "" ]] && _expuser=$(cat /etc/SSHPlus/Exp) || _expuser="0"
[[ -e /etc/openvpn/openvpn-status.log ]] && _onop=$(grep -c "10.8.0" /etc/openvpn/openvpn-status.log) || _onop="0"
[[ -e /etc/default/dropbear ]] && _drp=$(ps aux | grep dropbear | grep -v grep | wc -l) _ondrp=$(($_drp - 1)) || _ondrp="0"
_onli=$(($_ons + $_onop + $_ondrp))
echo -e "\033[1;37m• \033[1;36mTOTAL USUARIOS\033[1;37m $_tuser \033[1;37m• \033[1;32mONLINES\033[1;37m: $_onli \033[1;37m• \033[1;31mVENCIDOS\033[1;37m: $_expuser \033[1;37m•\033[0m"

read op
case $op in
1)clear
echo -e "\E[44;1;37m             BLOQUEAR USUÁRIO            \E[0m"
echo ""
echo " DIGITE O NOME DE USUÁRIO QUE DESEJA BLOQUEAR : "
read lock
passwd -l $lock
echo -e "\033[1;34m\033[1;37m\033[1;34m\033[1;37m \033[1;37mUSUÁRIO BLOQUEADO COM SUCESSO \033[0;32m"
echo -e ""
echo -e ""
echo -ne "\n\033[1;37mENTER \033[1;37mPARA VOLTAR AO \033[1;37mMENU!\033[0m"; read
clear
;;
2)clear
echo -e "\E[44;1;37m           DESBLOQUEAR USUÁRIO           \E[0m"
echo ""
echo " DIGITE O NOME DE USUÁRIO QUE DESEJA DESBLOQUEAR :   "
read unlock
passwd -u  $unlock
echo -e "\033[1;34m\033[1;37m\033[1;34m\033[1;37m \033[1;37mUSUÁRIO DESBLOQUEADO COM SUCESSO \033[0;32m"
echo -e ""
echo -e ""
echo -ne "\n\033[1;37mENTER \033[1;37mPARA VOLTAR AO \033[1;37mMENU!\033[0m"; read
clear
;;
0)clear
echo "RETORNANDO...."
menu
;;
*)clear
echo "Opcao Invalida ..."
sleep 1s
clear
;;
esac
done

